﻿using MangoMes.Commont.DapperHelps;
using MangoMes.Commont.Domain;
using MangoMes.Commont.Domain.Productions;
using MangoMes.Commont.DTOs;
using MangoMes.Commont.Infrastructures.Interfaces;
using MediatR;

namespace MangoMes.Write.API.Applications.Strippings
{
    public class StashBindHandler : IRequestHandler<StashBindCommand, ResultsDTO<WarehouselistDto>>
    {
        #region 仓储
        private readonly IBateRepository<WarehouselistDto> WarehouselistRepository;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="WarehouselistRepository"></param>
        public StashBindHandler(IBateRepository<WarehouselistDto> WarehouselistRepository)
        {
            this.WarehouselistRepository = WarehouselistRepository;
        }
        #endregion

        #region 下拉框 仓库
        /// <summary>
        /// 下拉框 仓库
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<ResultsDTO<WarehouselistDto>> Handle(StashBindCommand request, CancellationToken cancellationToken)
        {
            //异常处理
            try
            {
                //初始化一个ResultDTO<WarehouselistDto>对象result，并设置Code为 0
                ResultsDTO<WarehouselistDto> result = new ResultsDTO<WarehouselistDto>();
                //创建DapperHelper对象 用于与数据库进行交互
                DapperHelper dapperHelper = new DapperHelper();
                WarehouselistDto dto = new WarehouselistDto();

                //连接mySql 
                string conn = dapperHelper.MangoMesWrite;

                //sql语句
                string str = $"select * from warehouselist";

                var res = WarehouselistRepository.GetAll(str, dto, conn).ToList();

                result.Data = res;

                return result;
            }
            catch (Exception)
            {

                throw;
            }
        }
        #endregion

    }
}
